package com.ycy.pass;

import com.ycy.BaseTest;
import org.flowable.engine.repository.Deployment;
import org.flowable.engine.runtime.ProcessInstance;
import org.flowable.task.api.Task;
import org.junit.Test;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static com.ycy.RdfaBpCustomVarContants.*;

public class PassAndRejectDemo extends BaseTest {

  public static String OPERATE_TYPE_SUPER_OP = "superOp";
  public static String OPERATE_TYPE_REJECT = "reject";
  public static String OPERATE_TYPE_RESUBMIT = "resubmit";
  public static String OPERATE_TYPE_PASS = "pass";
  public static String OPERATE_TYPE_CANCEL_TASK = "cancelTask";
  public static String OPERATE_TYPE_CANCEL_PROCESS = "cancel";

  @Test
  public void create() {
    Deployment deploy = repositoryService.createDeployment().addClasspathResource("pass/abcdef.bpmn20.xml").deploy();
    System.out.println(deploy.getId());
    //设置流程变量
    HashMap<String, Object> map = new HashMap<>();
    //定义的人员列表4人
    String[] v = {"shareniu1", "shareniu2", "shareniu3", "shareniu4"};
    map.put("per", "60元/位置");
    map.put("money", "10000元");
    map.put("assigneeList", Arrays.asList(v));
    ProcessInstance pi = runtimeService.startProcessInstanceByKey("passAndReject", map);
    System.out.println("==> 流程实例启动 实例id :" + pi.getProcessInstanceId());
  }

  String procInstId = "4";

  @Test
  public void query() {
    List<Task> list1 = taskService.createTaskQuery().processInstanceId(procInstId).list();
    for (Task task : list1) {
      System.out.println(task);
    }
  }

  String ataskId = "26";

  @Test
  public void pass() {
    HashMap<String, Object> variables = new HashMap<>();
    variables.put(TASK_OPERATE_TYPE, OPERATE_TYPE_PASS);
    taskService.complete(ataskId, variables);
  }

  String taskId = "35003";

  @Test
  public void pass1() {
    Map<String, Object> map = new HashMap<>();
    map.put("approved", true);
    map.put(TASK_OPERATE_TYPE, OPERATE_TYPE_PASS);
    map.put(TASK_AUDIT_REASON, "批准");
    taskService.complete(taskId, map);
  }

  @Test
  public void reject() {
    Map<String, Object> map = new HashMap<>();
    map.put("approved", false);
    map.put(TASK_OPERATE_TYPE, OPERATE_TYPE_PASS);
    map.put(TASK_AUDIT_REASON, "驳回");
    taskService.complete(taskId, map);
  }

}
